home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 7: Sunsite / Linux Cubed Series 7 - Sunsite Vol 1.iso / system / admin / linuxcon.000 / linuxcon / linuxconf-1.6 / translate / msgupd.c < prev    next >
C/C++ Source or Header  |  1996-04-18  |  3KB  |  146 lines

  1. /* #Specification: translation / msgupd / intro
  2.     the msgupd utility update translated dictionnaries
  3.     using the dictionaries extracted from the C++ sources.
  4. */
  5. #include <stdarg.h>
  6. #include <stdio.h>
  7. #include <string.h>
  8. #include <stdlib.h>
  9. #include <limits.h>
  10. #include <sys/stat.h>
  11. #include <errno.h>
  12. #include "internal.h"
  13.  
  14. #ifdef UNIX
  15.     #define MAXIMUM_PATH    PATH_MAX
  16. #else
  17.     #define MAXIMUM_PATH    128
  18. #endif
  19.  
  20. /*
  21.     Print an error message in a popup
  22.     Stubs to avoid linking the world
  23. */
  24. void xconf_error (const char *msg, ...)
  25. {
  26.     va_list list;
  27.     va_start (list,msg);
  28.     vfprintf (stderr,msg,list);
  29.     va_end (list);
  30. }
  31.  
  32. static int msgupd_exist (const char *path)
  33. {
  34.     struct stat st;
  35.     return stat(path,&st)!= -1;
  36. }
  37.  
  38. static int msgupd_do (
  39.     const char *srcpath,
  40.     const char *dstpath,
  41.     const char *dict,
  42.     char lang)
  43. {
  44.     int ret = -1;
  45.     char path[PATH_MAX];
  46.     sprintf (path,"%s%s.dic",srcpath,dict);
  47.     if (!msgupd_exist (path)){
  48.         fprintf (stderr,"Dictionary %s does not exist\n",path);
  49.     }else{        
  50.         TR_STRINGS src;
  51.         if (src.read(path)!=-1){
  52.             if (src.getnb() == 0){
  53.                 fprintf (stderr,"Dictionary %s is empty\n",path);
  54.             }else{
  55.                 sprintf (path,"%s%s.dic",dstpath,dict);
  56.                 TR_STRINGS dst;
  57.                 dst.read (path);
  58.                 int n = src.getnb();
  59.                 printf ("Processing dictiotionnaryary %s\n",dict);
  60.                 for (int i=0; i<n; i++){
  61.                     TR_STRING *s = src.getitem(i);
  62.                     const char *id = s->getid();
  63.                     TR_STRING *d = dst.getitem(id);
  64.                     if (d == NULL){
  65.                         // New message
  66.                         d = new TR_STRING (id);
  67.                         dst.add (d);
  68.                     }
  69.                     const char *sm = s->getmsg(lang);
  70.                     LANG_STRING *dm = d->gettranslation(lang);
  71.                     if (sm == NULL){
  72.                     }else if (dm == NULL){
  73.                         d->settranslation (lang,sm);
  74.                         d->add2comment ("# *** new message\n");
  75.                     }else if (dm->str.cmp(sm)!=0){
  76.                         dm->lang = 'Z';
  77.                         d->settranslation (lang,sm);
  78.                         d->add2comment ("# *** updated message\n");
  79.                     }
  80.                 }
  81.                 ret = 0;
  82.                 if (dst.was_modified()){
  83.                     printf ("\tSome work to do in dictionary %s\n",dict);
  84.                     ret = dst.write_mod (path);
  85.                 }
  86.             }
  87.         }
  88.     }
  89.     return ret;
  90. }
  91.  
  92.  
  93. int main (int _argc, char *_argv[])
  94. {
  95.     char *argv[200];
  96.     int argc = anlparm (_argc,_argv,argv);
  97.     int ret = -1;
  98.     if (argc < 5){
  99.         fprintf (stderr,"msgupd -spath -dpath -rlang dictionnary ...\n");
  100.     }else{
  101.         ret = 0;
  102.         const char *srcpath = NULL;
  103.         const char *dstpath = NULL;
  104.         char lang = 'E';
  105.         for (int a=1; a<argc; a++){
  106.             char *arg = argv[a];
  107.             if (arg[0] == '-'){
  108.                 if (arg[1] == 's'){
  109.                     if (arg[2] == '\0'){
  110.                         a++;
  111.                         srcpath = argv[a];
  112.                     }else{
  113.                         srcpath = arg+2;
  114.                     }
  115.                 }else if (arg[1] == 'd'){
  116.                     if (arg[2] == '\0'){
  117.                         a++;
  118.                         dstpath = argv[a];
  119.                     }else{
  120.                         dstpath = arg+2;
  121.                     }
  122.                 }else if (arg[1] == 'r'){
  123.                     if (arg[2] == '\0'){
  124.                         a++;
  125.                         lang = argv[a][0];
  126.                     }else{
  127.                         lang = arg[2];
  128.                     }
  129.                 }else{
  130.                     fprintf (stderr,"Invalid option %s\n",arg);
  131.                     ret = -1;                
  132.                 }
  133.             }else if (dstpath == NULL || srcpath == NULL){
  134.                 fprintf (stderr,"Can't process dictionary %s\n"
  135.                     "Both -d and -s are needed\n",arg);
  136.                 ret = -1;                
  137.             }else if (ret == 0){
  138.                 ret = msgupd_do (srcpath,dstpath,arg,lang);
  139.             }
  140.         }
  141.     }
  142.     return ret;
  143. }
  144.  
  145.  
  146.